package com.taplinker.client.db.bean;

import android.content.ContentValues;

public class Message {
	public final static String MESSAGE_ID = "messageId";
	public final static String STATUS = "status";
	public final static String CONTENT = "content";
	public final static String MESSAGE_TIME = "messageTime";
	public final static String MESSAGE_TYPE = "messageType";
	public final static String CONVERSATION_ID = "conversationId";
	public final static String FROM = "from";
	public final static String TO = "to";
	public final static String REMARK = "remark";
	public final static String USER_ID = "userId";
	public final static String USER_NAME = "userName"; 
	public final static String USER_NICKNAME = "userNickname"; 
	
	private String messageId;
	private String status;
	private String content;
	private long messageTime;
	private String messageType;
	private String conversationId;
	private String from;
	private String to;
	private String remark;
	private String userId;
	private String userName;
	private String userNickname;
	
	public String getMessageId() {
		return messageId;
	}
	public void setMessageId(String messageId) {
		this.messageId = messageId;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public long getMessageTime() {
		return messageTime;
	}
	public void setMessageTime(long messageTime) {
		this.messageTime = messageTime;
	}
	public String getMessageType() {
		return messageType;
	}
	public void setMessageType(String messageType) {
		this.messageType = messageType;
	}
	public String getConversationId() {
		return conversationId;
	}
	public void setConversationId(String conversationId) {
		this.conversationId = conversationId;
	}
	public String getFrom() {
		return from;
	}
	public void setFrom(String from) {
		this.from = from;
	}
	public String getTo() {
		return to;
	}
	public void setTo(String to) {
		this.to = to;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getUserNickname() {
		return userNickname;
	}
	public void setUserNickname(String userNickname) {
		this.userNickname = userNickname;
	}
	
	public ContentValues convert2ContentValues() {
		ContentValues cv = new ContentValues();
		cv.put(MESSAGE_ID, messageId);
		cv.put(STATUS, status);
		cv.put(CONTENT, content);
		cv.put(MESSAGE_TIME, messageTime);
		cv.put(MESSAGE_TYPE, messageType);
		cv.put(CONVERSATION_ID, conversationId);
		cv.put(FROM, from);
		cv.put(TO, to);
		cv.put(REMARK, remark);
		cv.put(USER_ID, userId);
		cv.put(USER_NAME, userName);
		cv.put(USER_NICKNAME, userNickname);
		return cv;
	}
	
	public static ContentValues convert2ContentValues(Message msg) {
		ContentValues cv = null;
		if(msg != null) {
			cv = new ContentValues();
			cv.put(MESSAGE_ID, msg.getMessageId());
			cv.put(STATUS, msg.getStatus());
			cv.put(CONTENT, msg.getContent());
			cv.put(MESSAGE_TIME, msg.getMessageTime());
			cv.put(MESSAGE_TYPE, msg.getMessageType());
			cv.put(CONVERSATION_ID, msg.getConversationId());
			cv.put(FROM, msg.getFrom());
			cv.put(TO, msg.getTo());
			cv.put(REMARK, msg.getRemark());
			cv.put(USER_ID, msg.getUserId());
			cv.put(USER_NAME, msg.getUserName());
			cv.put(USER_NICKNAME, msg.getUserNickname());
		}
		return cv;
	}
	
	public static Message buildFromContentValues(ContentValues cv) {
		Message msg = null;
		if(cv != null) {
			msg = new Message();
			msg.setMessageId(cv.getAsString(MESSAGE_ID));
			msg.setStatus(cv.getAsString(STATUS));
			msg.setContent(cv.getAsString(CONTENT));
			msg.setMessageTime(cv.getAsLong(MESSAGE_TIME));
			msg.setMessageType(cv.getAsString(MESSAGE_TYPE));
			msg.setConversationId(cv.getAsString(CONVERSATION_ID));
			msg.setFrom(cv.getAsString(FROM));
			msg.setTo(cv.getAsString(TO));
			msg.setRemark(cv.getAsString(REMARK));
			msg.setUserId(cv.getAsString(USER_ID));
			msg.setUserName(cv.getAsString(USER_NAME));
			msg.setUserNickname(cv.getAsString(USER_NICKNAME));
		}
		return msg;
	}
}
